import {createRouter, createWebHistory} from "vue-router";
const BasicLayout = () => import("@/view/layouts/BasicLayout.vue");
const UserLoginPage = () => import("../view/login/UserLoginPage.vue");
const UserRegistPage = () => import("@/view/login/UserRegistPage.vue");
const ForgetPasswordPage = () => import("@/view/login/ForgetPasswordPage.vue");
const UserTagsPage = () => import("@/view/user/UserTagsPage.vue");
const UserChat = () => import("@/view/chat/UserChat.vue");
const AddBlog = () => import("@/view/blog/AddBlog.vue");
const BlogDetailPage = () => import("@/view/blog/BlogDetailPage.vue");
const LikeMessage = () => import("@/view/message/LikeMessage.vue");
const FollowMessage = () => import("@/view/message/FollowMessage.vue");
const CommentMessage = () => import("@/view/message/CommentMessage.vue");
const PrivateMessage = () => import("@/view/message/PrivateMessage.vue");

import routes from "./routes";
import { ref } from "vue";
const router = createRouter({
    history: createWebHistory(),
    routes:[
        {path:'/', component:BasicLayout, redirect:'/home', children:routes},
        {path: '/login', component: UserLoginPage},
        {path: '/regist', component: UserRegistPage},
        {path: '/forget', component: ForgetPasswordPage},
        {path: '/user/tags', component: UserTagsPage},
        {path: '/chat', component: UserChat},
        {path: '/blog/add', component: AddBlog},
        {path: '/blog/detail', component: BlogDetailPage},
        {path: '/message/like', component: LikeMessage},
        {path: '/message/follow', component: FollowMessage},
        {path: '/message/comments', component: CommentMessage},
        {path: '/message/private', component: PrivateMessage},
    ]
})
const DEFAULT_TITLE = '伙伴匹配'
const title = ref(DEFAULT_TITLE) 
const leftBack = ref(true)
const rightSearch = ref(false)
router.beforeEach((to) => {
  const toPath = to.path
  const route = routes.find((route) => route.path === toPath);
  title.value = route?.name ?? DEFAULT_TITLE;
  if(route?.path === '/home'||route?.path === '/team' ||route?.path === '/message' || route?.path ==='/user'){
    leftBack.value = false
  }else{
    leftBack.value = true
  }
  if(route?.path === '/home'){
    rightSearch.value = true
  }else {
    rightSearch.value = false
  }
})
export {title,leftBack,rightSearch}
export default router